package gdocsclassify.ui;

import gdocsclassify.GDOCSclassify;
import gdocsclassify.actions.ExitAction;
import gdocsclassify.actions.LoginAction;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.HeadlessException;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class GDOCSclassifyUI extends JFrame {

	public static GDOCSclassifyUI INSTANCE = new GDOCSclassifyUI();
	private GDOCSclassify client;
	private JTextField usernameText = new JTextField();
	private JPasswordField passwordText = new JPasswordField();
	
	/**
	 * @param args
	 */
	public static GDOCSclassifyUI get_instance() {
		return INSTANCE;
	}
	private GDOCSclassifyUI() throws HeadlessException {
		super(GDOCSclassify.APPLICATION_NAME);
	}
	public static void main(String[] args) {
		try {
	        UIManager.setLookAndFeel(
	            UIManager.getSystemLookAndFeelClassName());
	    } 
	    catch (UnsupportedLookAndFeelException e) {
	       // handle exception
	    }
	    catch (ClassNotFoundException e) {
	       // handle exception
	    }
	    catch (InstantiationException e) {
	       // handle exception
	    }
	    catch (IllegalAccessException e) {
	       // handle exception
	    }
        UIManager.put("swing.boldMetal", Boolean.FALSE);
        
        GDOCSclassifyUI app = GDOCSclassifyUI.get_instance();
        app.init();
        app.setVisible(true);
	}
	
	private void init()
	{
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.client = new GDOCSclassify();
		this.addComponentsToPane(this.getContentPane());
		this.pack();
	}
	
	private void addComponentsToPane(Container pane)
	{
		JPanel userPanel = new JPanel(new FlowLayout());
		JPanel passwordPanel = new JPanel(new FlowLayout());
		JPanel loginButtonsPanel = new JPanel(new FlowLayout());
		
		userPanel.setMaximumSize(new Dimension(200,40));
		passwordPanel.setMaximumSize(new Dimension(200,40));
		loginButtonsPanel.setMaximumSize(new Dimension(200,40));
		
		pane.setLayout(new BoxLayout(pane,BoxLayout.Y_AXIS));
		pane.add(userPanel);
		pane.add(passwordPanel);
		pane.add(loginButtonsPanel);
		
		LoginAction loginAction = new LoginAction(this.client, this);
		ExitAction exitAction = new ExitAction();
		JButton loginButton = new JButton(loginAction);
		JButton cancelLoginButton = new JButton(exitAction);
		loginButtonsPanel.add(loginButton);
		loginButtonsPanel.add(cancelLoginButton);
		
		JLabel usernameLabel = new JLabel("User Name");
		usernameText.setPreferredSize(new Dimension(80,20));
		userPanel.add(usernameLabel);
		userPanel.add(usernameText);
		
		JLabel passwordLabel = new JLabel("Password");
		passwordText.setPreferredSize(new Dimension(80,20));
		passwordPanel.add(passwordLabel);
		passwordPanel.add(passwordText);
	}

	public String getUsername()
	{
		return usernameText.getText();
	}
	
	public String getPassword()
	{
		String password = new String(passwordText.getPassword());
		return password;
	}
	public void loginSuccessful() {
		
		this.displayFilesToClassify();
	}
	
	private void displayFilesToClassify() {
	
		
	}
	
	
}
